﻿Imports Microforma.BEL
Imports Microforma.BLL
Public Class frmAddConfigurarEscaner
    Dim beEscaner As New BEL.EscanerBE
    Dim bllEscaner As New BLL.EscanerBL
    Public IdEscaner As Integer
    Private Sub CmdAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdAceptar.Click
        If Not ValidaForm() Then Exit Sub

        beEscaner.Nombre = TxtNombre.Text
        beEscaner.Descripcion = TxtDescripcion.Text
        beEscaner.Formato = LstTipoImage.SelectedIndex
        beEscaner.Resolucion = LstResolucion.Text

        beEscaner.Duplex = IIf(RbtDuplexNo.Checked, False, True)
        beEscaner.EliminarBlancos = ChkEliminarBlanco.Checked
        beEscaner.EliminarDesviacion = ChkEliminarDesviacion.Checked

        If RtbArchivoTif.Checked Then
            beEscaner.TipoArchivo = "TIF"
        ElseIf RbtPDF.Checked Then
            beEscaner.TipoArchivo = "PDF"
        ElseIf RbtJPG.Checked Then
            beEscaner.TipoArchivo = "JPG"
        ElseIf RbtPDFOCR.Checked Then
            beEscaner.TipoArchivo = "PDO"
        End If

        Dim StrResultado As String
        If IdEscaner <> 0 Then 'Actualiza
            beEscaner.IdEscaner = IdEscaner
            StrResultado = bllEscaner.Actualizar(beEscaner)
        Else
            StrResultado = bllEscaner.Add(beEscaner)
        End If


        If StrResultado = "OK" Then
            MsgBox("La configuración se creo correctamente.", MsgBoxStyle.Information, Me.Text)
            Me.Close()
        Else
            MsgBox("Error al crear el registro." & vbCrLf & StrResultado, MsgBoxStyle.Exclamation, Me.Text)
        End If

    End Sub

    Private Function ValidaForm() As Boolean
        If TxtNombre.Text.Trim = "" Then
            MsgBox("Ingrese nombre del perfil de escaner.", MsgBoxStyle.Information, Me.Text)
            Return False
        End If
        Return True

    End Function

    Private Sub frmAddConfigurarEscaner_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LstTipoImage.SelectedIndex = 0
        LstResolucion.SelectedIndex = 2
        Dim beEscaner As New BEL.EscanerBE

        If IdEscaner = 0 Then Exit Sub
        Call LoadEscanerValores()


    End Sub
    Sub LoadEscanerValores()
        Dim _DataTableEscaners As DataTable = bllEscaner.GetItemEscaner(IdEscaner)
        TxtNombre.Text = _DataTableEscaners.Rows(0)("Nombre")
        TxtDescripcion.Text = _DataTableEscaners.Rows(0)("Descripcion")
        LstTipoImage.SelectedIndex = _DataTableEscaners.Rows(0)("Formato")
        Select Case _DataTableEscaners.Rows(0)("resolucion")
            Case 100 : LstResolucion.SelectedIndex = 0
            Case 200 : LstResolucion.SelectedIndex = 1
            Case 240 : LstResolucion.SelectedIndex = 2
            Case 300 : LstResolucion.SelectedIndex = 3
            Case 400 : LstResolucion.SelectedIndex = 4
            Case 500 : LstResolucion.SelectedIndex = 5
            Case 600 : LstResolucion.SelectedIndex = 6
        End Select
        Select Case _DataTableEscaners.Rows(0)("TipoArchivo")
            Case "TIF" : RtbArchivoTif.Checked = True
            Case "PDF" : RbtPDF.Checked = True
            Case "PDO" : RbtPDFOCR.Checked = True
            Case "JPG" : RbtJPG.Checked = True
        End Select
        RbtDuplexSi.Checked = True
        RbtDuplexNo.Checked = IIf(_DataTableEscaners.Rows(0)("Duplex") = "0", True, False)
        ChkEliminarBlanco.Checked = IIf(_DataTableEscaners.Rows(0)("EliminarBlancos") = "1", True, False)
        ChkEliminarDesviacion.Checked = IIf(_DataTableEscaners.Rows(0)("EliminarDesviacion") = "1", True, False)

    End Sub
End Class